<template xmlns="http://www.w3.org/1999/html">
  <div v-loading="loading"
       element-loading-text="拼命加载中"
       element-loading-spinner="el-icon-loading"
       element-loading-background="rgba(0, 0, 0, 0.8)">
    <div v-if="!hasMessage">
      这边空空如也ε=(´ο｀*)))唉
    </div>
    <template>
      <el-card class="box-card"
               v-for="(message,index) of wallMessage"
               v-if="hasMessage">
        <div slot="header" class="clearfix">
          <span>标题：{{ message.message_title }}</span>
          <span style="margin-left: 40px"><i class="el-icon-timer" style="margin-right: 3px"/>{{ message.message_time }}</span>
          <span style="margin-left: 40px"><i style="margin-right: 3px"
                                             class="el-icon-user-solid"/>{{ message.message_userName }}</span>
          <span style="margin-left: 40px"><i class="el-icon-location-outline"
                                             style="margin-right: 3px"/>{{ message.message_address }}</span>
        </div>
        <div>
          <span style="padding: 2px 4px;word-wrap:break-word;line-height: 25px;font-size: 20px">{{
              message.message_content
            }}</span>


          <el-button style="float: right;margin-top: 5px" type="success"
                     @click="pass(message.message_id)"
                     class="el-icon-success">通过
          </el-button>
          <el-button style="float: right;margin-top: 5px;margin-right: 30px"
                     type="danger"
                     class="el-icon-error"
                     @click="noPass(message.message_id)">不通过
          </el-button>


        </div>
      </el-card>
      <el-pagination
          background
          layout="prev, pager, next"
          :total="total"
          :pagesize="sizeNum"
          @current-change="getCurrentPageNum">
      </el-pagination>
    </template>


  </div>
</template>

<script>
export default {
  name: "Message",
  data() {
    return {
      pageNum: 1,
      sizeNum: 6,
      total: 100,
      wallMessage: {},
      CommentCollapse: "1",
      comments: {},
      commentsLen: 0,
      user: "",
      isLogin: true,
      hasMessage: '',
      currentComment: '',
      loading: true
    }
  },
  methods: {
    getCurrentPageNum(num) {
      this.pageNum = num;

      this.getRequest(this.$store.state.baseUrl+"/message/findAllIs", {
        pageNum: (this.pageNum + ""),
        sizeNum: (this.sizeNum + "")

      }).then(resp => {
        if (resp) {
          this.wallMessage = resp.obj.allMessage;

        }
      })

    },


    getMessage() {
      this.getRequest(this.$store.state.baseUrl+"/message/findAllIsNot", {
        pageNum: (this.pageNum + ""),
        sizeNum: (this.sizeNum + "")

      }).then(resp => {
        if (resp) {
          this.hasMessage = (resp.obj.allMessage.length > 0);
          this.wallMessage = resp.obj.allMessage;
          this.total = parseInt(resp.obj.pagesNum) * 10;
          this.loading = false;
        }
      });
    },
    pass(message_id) {
      this.putRequest(this.$store.state.baseUrl+'/message/setMessageEnable', {
        message_id: message_id
      }).then(resp => {
        this.getMessage();
        this.$message({
          type: 'success',
          message: '审核通过'
        })
      })
    },
    noPass(message_id) {
      this.deleteRequest(this.$store.state.baseUrl+'/message/deleteOneById', {
        message_id: message_id
      }).then(resp => {
        this.getMessage();
        this.$message({
          type: 'error',
          message: '审核不通过'
        })
      })
    }

  },
  mounted() {
    this.getMessage();
    this.user = JSON.parse(window.sessionStorage.getItem("user"));

  },

}
</script>

<style scoped>
.box-card {
  margin-bottom: 10px;

}
</style>
